<?php
class hrd_pelamar_model extends MY_Model {
	var $nama_tabel = 'hrd_pelamar';
	
	function GetJSON() {
		$ls_sql	= "	SELECT	a.*, b.nama_departemen, c.nama_sub_departemen, d.nama_jenjang
					FROM	".$this->nama_tabel." a
					LEFT JOIN HRD_DEPARTEMEN b ON a.id_departemen_fk = b.id_departemen_pk
					LEFT JOIN HRD_SUB_DEPARTEMEN c ON a.id_sub_departemen_fk = c.id_sub_departemen_pk
					LEFT JOIN HRD_JENJANG_PENDIDIKAN d ON a.id_jenjang_pendidikan_fk = d.id_jenjang_pk
					WHERE	(UPPER(id_pelamar_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pelamar) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(nama_pelamar,'')) LIKE '%".strtoupper(post('keyword'))."%')
					AND UPPER(NVL(id_jenjang_pendidikan_fk,' ')) LIKE '%".strtoupper(post('id_jenjang_pendidikan_fk'))."%'
					AND tgl_lamaran BETWEEN 
							TO_DATE('".date_format3(post('tgl_awal'), 'YYYY-MM-DD')."','YYYY-MM-DD') AND 
							TO_DATE('".date_format3(post('tgl_akhir'), 'YYYY-MM-DD')."','YYYY-MM-DD')
					ORDER BY ".(post('sort')=='' ? 'id_pelamar_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			$this->db->delete($this->nama_tabel, array('id_pelamar_pk' => $arr_rule['id_pelamar_pk']));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetSingleView($id_pelamar_pk) {
		$sql = "select a.*, TO_CHAR(a.tgl_lahir,'DD/MM/YYYY') tgl_lahir, TO_CHAR(a.tgl_lamaran,'DD/MM/YYYY') tgl_lamaran
				from hrd_pelamar a
				where a.id_pelamar_pk = '".strtoupper($id_pelamar_pk)."'
				";

		$result = $this->db->query($sql);


		if($result->num_rows() == 1) {
			return $result->row_array();
		} else {
			return NULL;
		}

	}

	function cetak() {
		$ls_sql	= "	SELECT	a.*, b.nama_departemen, c.nama_sub_departemen, d.nama_jenjang
					FROM	".$this->nama_tabel." a
					LEFT JOIN HRD_DEPARTEMEN b ON a.id_departemen_fk = b.id_departemen_pk
					LEFT JOIN HRD_SUB_DEPARTEMEN c ON a.id_sub_departemen_fk = c.id_sub_departemen_pk
					LEFT JOIN HRD_JENJANG_PENDIDIKAN d ON a.id_jenjang_pendidikan_fk = d.id_jenjang_pk
					WHERE	(UPPER(id_pelamar_pk) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_pelamar) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NVL(nama_pelamar,'')) LIKE '%".strtoupper(post('keyword'))."%')
					AND UPPER(NVL(id_jenjang_pendidikan_fk,' ')) LIKE '%".strtoupper(post('id_jenjang_pendidikan_fk'))."%'
					ORDER BY ".(post('sort')=='' ? 'id_pelamar_pk' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
					
		return json_encode( $this->paging($ls_sql) );
	}

}
?>